<div class="header_menu">
    <div class="container">
        <div class="header-nav clearfix">
            <?php echo $this->partial('site/headermenu'); ?>
        </div>
    </div>
</div>
</div>
<div class="container breadcrumbs">
    <a href="<?php echo $this->url('shopfront/default'); ?>"><?php echo $this->translate('首页'); ?></a>
    <span class="sep">/</span><span><?php echo $this->translate('账户余额'); ?></span>
</div>
<div class="container">
    <div class="uc-full-box">
        <div class="row">
            <div class="span4">
                <?php echo $this->partial('shopfront/home/left_menu.phtml'); ?>
                <?php
                $yezfInfo  = $this->frontwebsite()->websitePaymentInfo('yezf');
                $yezfState = 0;
                if(isset($yezfInfo['paycheck_state']['checked']) and $yezfInfo['paycheck_state']['checked'] == 1) $yezfState = 1;
                ?>
            </div>
            <div class="span16">
                <div class="xm-line-box uc-box">
                    <h3 class="right-more-title">
                        <form class="form-search" style="margin: 0;" method="get">
                            <?php echo $this->translate('账户余额'); ?> [<font color="#dd4b39"><?php echo $this->frontwebsite()->shopPriceExtend($this->user_info->user_money); ?></font>]
                            <div class="pull-right">
                                <input type="text" name="search_content" value="<?php echo isset($_GET['search_content']) ? $this->escapehtml($_GET['search_content']) : ''; ?>" placeholder="<?php echo $this->translate('输入金额或备注信息'); ?>" style="height:16px;width: 240px;padding-top: 5px;margin-bottom: 3px;">&nbsp;<button type="submit" class="btn btn-small btn-primary" style="width: 50px;"><?php echo $this->translate('搜索'); ?></button>
                            </div>
                        </form>
                    </h3>
                    <div class="box-hd-more">
                        <div class="span16">
                            <div class="span12 pull-left left-menu-more">
                                <div class="uc-order-list-type">
                                    <?php echo $this->partial('shopfront/home/home-money-menu.phtml'); ?>
                                </div>
                            </div>
                            <div class="span4 pull-right">
                                <?php if($yezfState == 1) { ?>
                                <a href="javascript:;" onclick="my_pay_to();" class="btn btn-primary btn-small"><?php echo $this->translate('充值'); ?></a>
                                <?php } ?>
                                <a href="javascript:;" class="btn btn-danger btn-small" onclick="money_oper();"><?php echo $this->translate('提现'); ?></a>
                            </div>
                        </div>
                    </div>
                    <div class="box-bd">
                        <?php
                        if ($this->user_paycheck_log->getTotalItemCount() > 0){
                            $type_array = array(1=>$this->translate('充值'), 2=>$this->translate('消费'), 3=>$this->translate('提现'), 4=>$this->translate('退款'));
                            ?>
                            <table class="table table-bordered table-hover" style="margin-top: 15px;">
                                <thead>
                                <tr>
                                    <th width="15%"><?php echo $this->translate('时间'); ?></th>
                                    <th width="12%"><?php echo $this->translate('充值金额'); ?></th>
                                    <th width="12%"><?php echo $this->translate('支付方式'); ?></th>
                                    <th width="8%"><?php echo $this->translate('状态'); ?></th>
                                    <th width="12%"><?php echo $this->translate('操作者'); ?></th>
                                    <th width="12%"><?php echo $this->translate('完成时间'); ?></th>
                                    <th width="43%"><?php echo $this->translate('备注'); ?></th>
                                </tr>
                                </thead>
                                <?php foreach ($this->user_paycheck_log as $log_value) { ?>
                                    <tr>
                                        <td><?php echo date("Y-m-d H:i:s", $log_value['paycheck_time']); ?></td>
                                        <td><?php echo $this->frontwebsite()->shopPrice($log_value['money_change_num']); ?></td>
                                        <td><?php echo !empty($log_value['pay_name']) ? $log_value['pay_name'] : $this->translate('系统充值'); ?></td>
                                        <td>
                                            <?php
                                            if($log_value['pay_state'] == 10) echo $this->translate('未完成').'&nbsp;<a href="'.$this->url('frontmoney/default/paycheck_id', array('action'=>'paycheckPay', 'paycheck_id'=>$log_value['paycheck_id'])).'" class="btn btn-primary">'.$this->translate('去支付').'</a>';
                                            if($log_value['pay_state'] == 20) echo '<font color="green">'.$this->translate('已完成').'</font>';
                                            ?>
                                        </td>
                                        <td>
                                            <?php
                                            if(!empty($log_value['admin_id']) and $log_value['admin_id'] != 0) echo '<strong>'.$this->translate('管理员').'</strong>';
                                            else echo $log_value['user_name'];
                                            ?>
                                        </td>
                                        <td>
                                            <?php echo !empty($log_value['paycheck_finish_time']) ? date("Y-m-d H:i:s", $log_value['paycheck_finish_time']) : ''; ?></td>
                                        </td>
                                        <td><?php echo $this->escapeHtml($log_value['paycheck_info']); ?></td>
                                    </tr>
                                <?php } ?>
                            </table>
                            <div>
                                    <?php echo ( count($this->user_paycheck_log) > 0 ) ? $this->paginationControl($this->user_paycheck_log, 'Sliding', 'site/dbpage',array('page_url'=>$this->url('frontmoney/default', $this->page_action))) : ""; ?>
                            </div>
                        <?php } else { ?>
                            <?php echo $this->translate('暂无记录！'); ?>
                        <?php } ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php if($yezfState == 1) { ?>
<div id="myPayState" class="modal hide fade" style="width: 620px;height: 150px;" tabindex="-1" role="dialog" aria-labelledby="myPayStateLabel" aria-hidden="true">
    <div class="modal-header" style="border-bottom: 0;">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myPayStateLabel"><?php echo $this->translate('充值处理情况'); ?></h3>
        <div class="modal-body" style="text-align: center;vertical-align: middle;">
            <a href="<?php echo $this->url('frontmoney/default', array('action'=>'paychecklog')); ?>" class="btn btn-large btn-success" style="margin-right: 10px;"><?php echo $this->translate('已经完成充值'); ?></a>
            <a href="<?php echo $this->url('frontmoney/default', array('action'=>'paychecklog')); ?>" class="btn btn-large btn-danger" style="margin-left: 10px;"><?php echo $this->translate('未完成充值'); ?></a>
        </div>
    </div>
</div>

<form class="form-horizontal" name="user_pay_form" id="user_pay_form" method="post">
    <input type="hidden" name="pay_name" id="pay_name" value="">
    <div id="myPayModal" class="modal hide fade" style="width: 620px;" tabindex="-1" role="dialog" aria-labelledby="myPayModalLabel" aria-hidden="true">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="myPayModalLabel"><?php echo $this->translate('账户充值操作'); ?></h3>
        </div>
        <div class="modal-body">
            <div class="control-group">
                <label class="control-label"><?php echo $this->translate('选择支付方式'); ?><span class="must_add_value">*</span></label>
                <div class="controls">
                    <select name="payment_code" id="payment_code" class="span2">
                        <?php
                        if($this->payment) {
                            foreach($this->payment as $pay_value) {
                                ?>
                                <option value="<?php echo $pay_value['editaction']; ?>"><?php echo $this->escapeHtml($pay_value['payment_name']['content']); ?></option>
                            <?php } } ?>
                    </select>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"><?php echo $this->translate('填写充值金额'); ?><span class="must_add_value">*</span></label>
                <div class="controls">
                    <input type="text" name="pay_change_num" id="pay_change_num" value="" class="span2">
                </div>
            </div>

        </div>
        <div class="modal-footer">
            <button type="submit" class="btn btn-primary"><?php echo $this->translate('立刻充值'); ?></button>
            &nbsp;&nbsp;
            <button class="btn" data-dismiss="modal" aria-hidden="true"><?php echo $this->translate('关闭'); ?></button>
        </div>
    </div>
</form>
<?php } ?>
<form class="form-horizontal" name="user_money_form" id="user_money_form" method="post">
    <div id="myModal" class="modal hide fade" style="width: 620px;" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="myModalLabel"><?php echo $this->translate('余额提现操作'); ?></h3>
        </div>
        <div class="modal-body">
            <div class="control-group">
                <label class="control-label"><?php echo $this->translate('可提现金额'); ?></label>
                <div class="controls">
                    <label style="color: red;height: 30px;line-height: 30px;">
                        <?php echo $this->frontwebsite()->shopPriceExtend($this->user_info->user_money); ?>
                    </label>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"><?php echo $this->translate('提现金额'); ?><span class="must_add_value">*</span></label>
                <div class="controls">
                    <input type="text" name="money_change_num" id="money_change_num" value="" class="span3">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"><?php echo $this->translate('支付名称/开户银行'); ?><span class="must_add_value">*</span></label>
                <div class="controls">
                    <input type="text" name="bank_name" id="bank_name" value="" class="span3" placeholder="<?php echo $this->translate('支付名称如 支付宝'); ?>">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"><?php echo $this->translate('账户名称/开户名称'); ?><span class="must_add_value">*</span></label>
                <div class="controls">
                    <input type="text" name="bank_account" id="bank_account" value="" class="span3">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"><?php echo $this->translate('账号/卡号'); ?><span class="must_add_value">*</span></label>
                <div class="controls">
                    <input type="text" name="bank_card_number" id="bank_card_number" value="" class="span3">
                </div>
            </div>

        </div>
        <div class="modal-footer">
            <button type="submit" class="btn btn-primary"><?php echo $this->translate('申请提现'); ?></button>
            &nbsp;&nbsp;
            <button class="btn" data-dismiss="modal" aria-hidden="true"><?php echo $this->translate('关闭'); ?></button>
        </div>
    </div>
</form>
<script>
    $(document).ready(function() {
        <?php if($yezfState == 1) { ?>
        $("#user_pay_form").validate({
            rules: {
                pay_change_num: {
                    required: true,
                    number: true,
                    min: 1
                },
                payment_code: {
                    required: true
                }
            },
            messages: {
                pay_change_num: {
                    required: "<?php echo $this->translate('充值金额不能为空！'); ?>",
                    number: "<?php echo $this->translate('充值金额必须为数字！'); ?>",
                    min: "<?php echo $this->translate('充值金额最小为 1'); ?>"
                },
                payment_code: {
                    required: "<?php echo $this->translate('请选择支付方式'); ?>"
                }
            },
            submitHandler:function(form){
                to_pay_oper();
            }
        });
        <?php } ?>
        $("#user_money_form").validate({
            rules: {
                money_change_num: {
                    required: true,
                    number: true,
                    min: 0.01,
                    max: <?php echo $this->frontwebsite()->shopPrice($this->user_info->user_money); ?>
                },
                bank_name: {
                    required: true
                },
                bank_account: {
                    required: true
                },
                bank_card_number: {
                    required: true
                }
            },
            messages: {
                money_change_num: {
                    required: "<?php echo $this->translate('提现金额不能为空！'); ?>",
                    number: "<?php echo $this->translate('提现金额必须为数字！'); ?>",
                    min: "<?php echo $this->translate('提现金额最小为 0.01'); ?>",
                    max: "<?php echo $this->translate('提现金额最大为 ').$this->frontwebsite()->shopPrice($this->user_info->user_money); ?>"
                },
                bank_name: {
                    required: "<?php echo $this->translate('支付名称/开户银行 不能为空！'); ?>"
                },
                bank_account: {
                    required: "<?php echo $this->translate('账户名称/开户名称 不能为空！'); ?>"
                },
                bank_card_number: {
                    required: "<?php echo $this->translate('账号/卡号 不能为空！'); ?>"
                }
            },
            submitHandler:function(form){
                save_money_oper();
            }
        });
    });

    <?php if($yezfState == 1) { ?>
    //充值操作
    function my_pay_to() {
        $('#myPayModal').modal('show');
    }
    //充值处理
    function to_pay_oper() {
        var pay_name = $("#payment_code").find("option:selected").text();
        $("#pay_name").val(pay_name);

        $.post("<?php echo $this->url('frontmoney/default', array('action'=>'mypayto')); ?>",$('#user_pay_form').formSerialize(),
            function(data){
                if(data.state == 'true') {
                    //window.open(data.pay_url);
                    window.location.href= data.pay_url;
                    //$('#myPayModal').modal('hide');
                    //$('#myPayState').modal('show');
                } else {
                    alert(data.message);
                    return false;
                }
            }, 'json');
    }
    <?php } ?>
    //提现操作
    function money_oper() {
        $.post("<?php echo $this->url('frontmoney/default', array('action'=>'infowithdraw')); ?>",{},
            function(data){
                if(data == 'true') {
                    $('#myModal').modal('show');
                } else {
                    alert(data);
                    return false;
                }
            });
    }
    //提现处理
    function save_money_oper() {
        $.post("<?php echo $this->url('frontmoney/default', array('action'=>'addwithdraw')); ?>",$('#user_money_form').formSerialize(),
            function(data){
                if(data == 'true') {
                    window.location.href="<?php echo $this->url('frontmoney/default', array('action'=>'withdrawlog')); ?>";
                } else {
                    alert(data);
                    return false;
                }
            });
    }
</script>